//
//  TitleButton.swift
//  mySwift
//
//  Created by 高赛 on 16/9/19.
//  Copyright © 2016年 高赛. All rights reserved.
//

import UIKit

class TitleButton: UIButton {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setTitleColor(UIColor.darkText, for: [])
        titleLabel?.font = UIFont.systemFont(ofSize: 17)
        setImage(UIImage(named: "navigationbar_arrow_down"), for: [])
        setImage(UIImage(named: "navigationbar_arrow_up"), for: UIControlState.selected)
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        /*  
        // 系统会调用两次
        titleLabel?.frame.offsetBy(dx: -imageView!.bounds.width, dy: 0)
        imageView?.frame.offsetBy(dx: titleLabel!.bounds.width, dy: 0)
        */
        titleLabel?.frame.origin.x = 0
        imageView?.frame.origin.x = titleLabel!.frame.size.width
        
    }

}
